﻿using System;
using Styx;

namespace SuperbadWoD
{
    internal class Moonkin
    {
        public static int active_enemies { get; set; }
        public static double eclipse_change { get; set; }
        public static int eclipse_energy { get; set; }
        public static int eclipse_max { get; set; }

        public void UpdateMoonkinVariables()
        {
            active_enemies = active_enemies;
            eclipse_change = eclipse_change;
            eclipse_energy = eclipse_energy;
            eclipse_max = eclipse_max;
            action.force_of_nature.charges = action.force_of_nature.charges;
            action.starfire.execute_time = action.starfire.execute_time;
            action.starsurge.charges = action.starsurge.charges;
            action.wrath.execute_time = action.wrath.execute_time;
            buff.bloodlust.react = buff.bloodlust.react;
            buff.celestial_alignment.remains = buff.celestial_alignment.remains;
            buff.celestial_alignment.up = buff.celestial_alignment.up;
            buff.lunar_empowerment.up = buff.lunar_empowerment.up;
            buff.solar_empowerment.up = buff.solar_empowerment.up;
            cooldown.celestial_alignment.remains = cooldown.celestial_alignment.remains;
            dot.moonfire.remains = dot.moonfire.remains;
            dot.moonfire.ticking = dot.moonfire.ticking;
            dot.stellar_flare.ticking = dot.stellar_flare.ticking;
            dot.sunfire.remains = dot.sunfire.remains;
            dot.sunfire.ticking = dot.sunfire.ticking;
            eclipse_dir.lunar = eclipse_dir.lunar;
            talent.balance_of_power.enabled = talent.balance_of_power.enabled;
            talent.euphoria.enabled = talent.euphoria.enabled;
            target.time_to_die = target.time_to_die;
        }

        public static void MoonkinRotation()
        {
            if (buff.bloodlust.react || target.time_to_die <= 40 || buff.celestial_alignment.up)
                draenic_intellect();
            if (buff.bloodlust.react || target.time_to_die <= 40 || buff.celestial_alignment.up)
                blood_fury();
            if (buff.bloodlust.react || target.time_to_die <= 40 || buff.celestial_alignment.up)
                berserking();
            if (buff.bloodlust.react || target.time_to_die <= 40 || buff.celestial_alignment.up)
                use_item(WoWInventorySlot.Trinket1);
            if (active_enemies == 1 && talent.euphoria.enabled)
            {
                euphoria();
                return;
            }
            if (active_enemies == 1 && talent.balance_of_power.enabled)
            {
                bop();
                return;
            }
            if (active_enemies == 1)
            {
                single_target();
                return;
            }
            if (active_enemies > 1)
                aoe();
        }

        private static void draenic_intellect()
        {
            throw new NotImplementedException();
        }

        private static void use_item(WoWInventorySlot trinket1)
        {
            throw new NotImplementedException();
        }

        private static void aoe()
        {
            if (celestial_alignment())
                return;
            if ((eclipse_dir.lunar && eclipse_max >= 5) || eclipse_energy <= 10)
                if (incarnation())
                    return;
            if (starfall())
                return;
            //TODO:CYCLE
            if (!dot.stellar_flare.ticking)
                if (stellar_flare())
                    return;
            //TODO:CYCLE
            if (!dot.moonfire.ticking ||
                (dot.moonfire.remains <= 8 && eclipse_change <= 12 && eclipse_energy == 100 && eclipse_change >= 8) ||
                (buff.celestial_alignment.up && dot.moonfire.ticking && dot.sunfire.ticking && dot.sunfire.remains <= 6))
                if (moonfire())
                    return;
            //TODO:CYCLE
            if (!dot.sunfire.ticking || (eclipse_energy < 0 && dot.sunfire.remains <= 8))
                if (sunfire())
                    return;
            if (buff.celestial_alignment.up && buff.solar_empowerment.up && eclipse_energy < 0)
                if (wrath())
                    return;
            if (buff.celestial_alignment.up && buff.lunar_empowerment.up && eclipse_energy >= 0)
                if (starfire())
                    return;
            if ((eclipse_energy > 0 && eclipse_change > action.starfire.execute_time) ||
                (eclipse_energy < 0 && eclipse_change < action.starfire.execute_time))
                if (starfire())
                    return;
            if ((eclipse_energy < 0 && eclipse_change > action.wrath.execute_time) ||
                (eclipse_energy > 0 && eclipse_change < action.wrath.execute_time))
                wrath();
        }

        private static bool stellar_flare()
        {
            throw new NotImplementedException();
        }

        private static bool moonfire()
        {
            throw new NotImplementedException();
        }

        private static bool starfire()
        {
            throw new NotImplementedException();
        }

        private static bool wrath()
        {
            throw new NotImplementedException();
        }

        private static bool sunfire()
        {
            throw new NotImplementedException();
        }

        private static bool starfall()
        {
            throw new NotImplementedException();
        }

        private static bool incarnation()
        {
            throw new NotImplementedException();
        }

        private static bool celestial_alignment()
        {
            throw new NotImplementedException();
        }

        private static void single_target()
        {
            if (eclipse_change <= 2 || (eclipse_energy <= 20 && !dot.stellar_flare.ticking) ||
                (buff.celestial_alignment.up && buff.celestial_alignment.remains <= 2))
                if (stellar_flare())
                    return;
            if (action.force_of_nature.charges >= 1)
                force_of_nature();
            if ((eclipse_dir.lunar && eclipse_max >= 5) || eclipse_energy <= 10)
                if (celestial_alignment())
                    return;
            if ((eclipse_dir.lunar && eclipse_max >= 5) || eclipse_energy <= 10)
                if (incarnation())
                    return;
            if (action.starsurge.charges == 3 && cooldown.celestial_alignment.remains > 10)
                if (starsurge())
                    return;
            if (!dot.moonfire.ticking || (eclipse_max == 0 && dot.moonfire.remains <= 25))
                if (moonfire())
                    return;
            if (!dot.sunfire.ticking || dot.sunfire.remains <= 6 ||
                (buff.celestial_alignment.up && buff.celestial_alignment.remains <= 2))
                if (sunfire())
                    return;
            if (buff.lunar_empowerment.up)
                if (starfire())
                    return;
            if (buff.solar_empowerment.up)
                if (wrath())
                    return;
            if (eclipse_energy >= 0 || (eclipse_energy <= 0 && eclipse_change < 2))
                if (starfire())
                    return;
            if (buff.celestial_alignment.up || eclipse_max <= 3 ||
                (action.starsurge.charges == 2 && cooldown.celestial_alignment.remains > 30))
                if (starsurge())
                    return;
            wrath();
        }

        private static bool starsurge()
        {
            throw new NotImplementedException();
        }

        private static void force_of_nature()
        {
            throw new NotImplementedException();
        }

        private static void bop()
        {
            if (action.force_of_nature.charges >= 1)
                force_of_nature();
            if ((eclipse_dir.lunar && eclipse_max >= 5) || eclipse_energy <= 10)
                if (incarnation())
                    return;
            if ((eclipse_dir.lunar && eclipse_max >= 5) || eclipse_energy <= 10)
                if (celestial_alignment())
                    return;
            if (action.starsurge.charges == 3 && cooldown.celestial_alignment.remains > 10)
                if (starsurge())
                    return;
            if (!dot.moonfire.ticking || (eclipse_max == 0 && dot.moonfire.remains <= 16))
                if (moonfire())
                    return;
            if (!dot.sunfire.ticking || dot.sunfire.remains <= 4 ||
                (buff.celestial_alignment.up && buff.celestial_alignment.remains <= 2))
                if (sunfire())
                    return;
            if (buff.lunar_empowerment.up)
                if (starfire())
                    return;
            if (buff.solar_empowerment.up)
                if (wrath())
                    return;
            if (eclipse_energy >= 0 || (eclipse_energy <= 0 && eclipse_change < 2))
                if (starfire())
                    return;
            if (buff.celestial_alignment.up || eclipse_max <= 3 ||
                (action.starsurge.charges == 2 && cooldown.celestial_alignment.remains > 30))
                if (starsurge())
                    return;
            wrath();
        }

        private static void euphoria()
        {
            if (action.force_of_nature.charges >= 1)
                force_of_nature();
            if ((eclipse_dir.lunar && eclipse_max >= 5) || eclipse_energy <= 10)
                if (incarnation())
                    return;
            if ((eclipse_dir.lunar && eclipse_max >= 5) || eclipse_energy <= 10)
                if (celestial_alignment())
                    return;
            if (action.starsurge.charges == 3 && cooldown.celestial_alignment.remains > 10)
                if (starsurge())
                    return;
            if (!dot.moonfire.ticking || (eclipse_max == 0 && dot.moonfire.remains <= 16))
                if (moonfire())
                    return;
            if (!dot.sunfire.ticking || (eclipse_max == 0 && dot.sunfire.remains <= 4) ||
                (buff.celestial_alignment.up && buff.celestial_alignment.remains <= 2))
                if (sunfire())
                    return;
            if (buff.lunar_empowerment.up)
                if (starfire())
                    return;
            if (buff.solar_empowerment.up)
                if (wrath())
                    return;
            if (eclipse_energy >= 0 || (eclipse_energy <= 0 && eclipse_change < 2))
                if (starfire())
                    return;
            if (buff.celestial_alignment.up || eclipse_max <= 3 ||
                (action.starsurge.charges == 2 && cooldown.celestial_alignment.remains > 30))
                if (starsurge())
                    return;
            wrath();
        }

        private static void berserking()
        {
            throw new NotImplementedException();
        }

        private static void blood_fury()
        {
            throw new NotImplementedException();
        }

        internal class action
        {
            public class force_of_nature
            {
                public static int charges { get; set; }
            }

            public class starfire
            {
                public static double execute_time { get; set; }
            }

            public class starsurge
            {
                public static int charges { get; set; }
            }

            public class wrath
            {
                public static double execute_time { get; set; }
            }
        }

        public class buff
        {
            public class bloodlust
            {
                public static bool react { get; set; }
            }

            public class celestial_alignment
            {
                public static bool up { get; set; }
                public static double remains { get; set; }
            }

            public class lunar_empowerment
            {
                public static bool up { get; set; }
            }

            public class solar_empowerment
            {
                public static bool up { get; set; }
            }
        }

        internal class cooldown
        {
            public class celestial_alignment
            {
                public static double remains { get; set; }
            }
        }

        internal class dot
        {
            public class moonfire
            {
                public static bool ticking { get; set; }
                public static double remains { get; set; }
            }

            public class stellar_flare
            {
                public static bool ticking { get; set; }
            }

            public class sunfire
            {
                public static bool ticking { get; set; }
                public static double remains { get; set; }
            }
        }

        internal class eclipse_dir
        {
            public static bool lunar { get; set; }
        }

        public class talent
        {
            public class balance_of_power
            {
                public static bool enabled { get; set; }
            }

            public class euphoria
            {
                public static bool enabled { get; set; }
            }
        }

        public class target
        {
            public static double time_to_die { get; set; }
        }
    }
}